package com.UnionPayCenter.account.enums;

import com.UnionPayCenter.enums.CodeBaseEnum;
import com.UnionPayCenter.exception.ApiException;
import lombok.Getter;

/**
 * 账户类型
 * 是否现金账户，配置在枚举中,优先级直接使用code
 */
public enum AccountTypeEnum implements CodeBaseEnum {

    POINTS(0, "积分账户", false),
    CHARGE(1, "充值账户", true),
    CASH_REWARDS(2, "赠送金额账户", true),
    DISTRIBUTION_CHARGE(3, "分销账户", true),
    ;

    /**
     * 账户类型代码
     * 也代表支付优先级(相同类型中才有效，比如都是现金账户)
     */
    private int code;

    /**
     * 是否现金账户
     */
    @Getter
    private boolean cash;

    private String msg;

    AccountTypeEnum(int code, String msg, boolean cash) {
        this.code = code;
        this.msg = msg;
        this.cash = cash;
    }

    public static AccountTypeEnum getEnum(int code) {
        for (AccountTypeEnum ele : AccountTypeEnum.values()) {
            if (ele.code == code) {
                return ele;
            }
        }
        throw new ApiException(404, "不正确的账户类型");
    }

    @Override
    public int code() {
        return this.code;
    }

    @Override
    public String msg() {
        return msg;
    }
}
